<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>个人中心</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<!--内容主体区域-->
    <div class="layui-container" style="margin-top: 50px; width: 100%;">
        <form class="layui-form layuimini-form" th:object="${zhanghao}">

            <input type="hidden" name="u_id" class="layui-input" th:field="*{z_id}">
            <div class="layui-form-item">
                <label class="layui-form-label required">账号</label>
                <div class="layui-input-block">
                    <input type="text" readonly="readonly" name="username" class="layui-input" th:field="*{username}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">密码</label>
                <div class="layui-input-block">
                    <input type="password" id="password"  name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" id="password2" name="password2" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
                </div>
            </div>
        </form>
    </div>
</div>


<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['element','form','upload'], function () {
        var form = layui.form,
            element=layui.element,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
        var params = data.field;
        var pwd = $("#password").val();
        var pwd2 = $("#password2").val();
        console.log(pwd);
        console.log(pwd2);

            if(pwd !== pwd2){
                parent.layer.msg("密码不一致，请重新输入！");
            }else {
                $.ajax({
                    type: 'POST',
                    url: window.location.protocol + '//' + window.location.host + '/updatePassword',
                    dataType: 'html',
                    data: JSON.stringify(params),
                    contentType: 'application/json',
                    success: function (data) {
                        parent.layer.msg("密码修改成功！");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        // setTimeout( function(){
                        //     window.location.href = 'toQzIndex';   //登录成功进行主页面
                        // }, 2 * 1000 );//延迟2秒
                    },
                    error: function () {
                        //console.log(data);
                        // layer.close(registerLoadIndex);
                        layer.alert("系统异常，请稍后重试！！")
                    }
                });
            }
            return false;
        });
    });
</script>
</body>
</html>